<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>首页 - 点滴</title>
		<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
		<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
		<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>		

		<style>
		
		@font-face {
		  font-family: 'iconfont';  /* project id 416894 */
		  src: url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.eot');
		  src: url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.eot?#iefix') format('embedded-opentype'),
		  url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.woff') format('woff'),
		  url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.ttf') format('truetype'),
		  url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.svg#iconfont') format('svg');
		}
				
			body{
				margin: 0;
				padding: 0;
				background-color: #f3f3f3;
			}
			a{
				color: inherit;
				text-decoration: none;
			}
			a:hover{
				color: #3879d9;
				text-decoration: none;
			}
			.top{
				display: flex;
				width: 100%;
				height: 50px;
				background-color: white;
				position: fixed;
				top: 0;
				box-shadow: 0px 2px 5px #888888;
			}
			.mid{
				margin-top: 60px;
				margin-left: auto;
				margin-right: auto;
				width: 75%;
			}
			
		.mid_left{
			padding: 3px;
			float: left;
			width: 65%;
		}
		
		.mid_right{
			padding: 3px;
			position: fixed;
			float: left;
			width: 24%;
			right: 13%;
		}
		
		.weibo_message{
			margin-top: 8px;
			background-color: white;
			min-height: 100px;
			box-shadow: 2px 3px 5px #888888;
		}
		
		.weibo_top{
			padding: 8px;
			padding-bottom: 5px;
			display: flex;
		}
		
		.weibo_message_img{
			width: 40px;
			height: 40px;
			background-color: black;
		}
		
		.weibo_message_nickname{
			margin-left: 8px;
			margin-top: 10px;
		}
		
		.div_message_mid{
			padding: 8px;
			padding-top: 5px;
		}
		
		.textarea_message{
			text-indent: 30px;
			padding-left: 8px;
			font-size: 15px;
			font-weight: bold;
		}
		
		.div_message_bottom{
			display: flex;
			/*padding: 8px;*/
			
		}
		
		
		.head_img{
			width: 50px;
			height: 50px;
		}
		
		.head_nickname{
			flex: 1;
			height: 50px;
		}
		
		.btn_bottom{
			text-align: center;
			font-family: "iconfont" !important;
			flex: 1;
			cursor: pointer;
			padding: 8px;
		}

		.btn_bottom:hover{
			background: #cceeff;
		}

		
		.right_weibo_top{
			padding: 8px;
			padding-top: 10px;
			padding-left: 12px;
			display: flex;
		}
		
		.right_weibo_message_img{
			width: 55px;
			height: 55px;
			background-color: black;
		}
		
		.right_nickname{
			padding: 8px;
			padding-left: 15px;
			font-size: 18px;
			font-weight: bold;
		}
		
		.friend_and_folloow{
			display: flex;
		}
		
		.follow{
			flex: 1;
			text-align: center;
			padding-top: 25px;
			padding: 10px;
			font-size: 19px;
			font-weight: bold;
		}
		
		.friend{
			flex: 1;
			text-align: center;
			padding-top: 25px;
			padding: 10px;
			font-size: 19px;
			font-weight: bold;
		}
		
		.right_common{
			padding: 10px;
			padding-top: 15px;
		}
		
		.right_common_in{
			padding: 3px;
			padding-top: 8px;
		}
		
		.weibo_edit{
			padding: 3px;
			background-color: white;
			box-shadow: 2px 3px 5px #888888;

		}
		
		.textarea_edit{
			padding: 3px;
			resize: none;
			width: 98%;
			height: 100px;
			
		}

		.btn_send{
			float: right;
		}
		
		.limit{
			padding: 3px;
		}
		
		.wright_number{
			padding: 3px;
			padding-left: 400px;
		}
		/*css的代码是按顺序优先执行的*/
		.logo{
			height: 40px;
			padding: 5px;
			padding-left: 200px;
		}
		
		.top_left{
			flex: 1;
		}
		
		.top_mid{
			flex: 1;
			font-family: "iconfont" !important;
			text-align: center;
			padding: 13px;
			padding-left: 15px;
		}
		
		.top_right{
			flex: 1;
		}
		
		.top_find{
			
			padding: 3px;
			
		}
		
		.top_img{
			width: 30px;
			height: 30px;
			background-color: blue;
		}
		
		.top_right{
			padding: 10px;
			padding-left: 80px;
		}
		
		.left_top{
			padding: 5px;
			background-color: white;
			box-shadow: 2px 3px 5px #888888;
		}
		
		.left_bottom{
			margin-top: 8px;
			padding: 5px;
			background-color: white;
			box-shadow: 2px 3px 5px #888888;
			font-size: 16px;
			font-weight: bold;
		}
		.edit_bottom{
			/*text-align: right;*/
			display: flex;
		}
		.edit_bottom_left{
			flex: 1;
		}
		.edit_bottom_right{

		}
		.edit_bottom_word_count{
			margin-right: 8px;
		}
		.send_btn{
			padding: 4px 8px 4px 8px;
			color: #fff;
			background: #00aaff;
			border: none;
			border-radius: 4px;
		}
		.search_btn{
			font-size: 20px;
			padding: 4px 8px 4px 8px;
			color: #000;
		}
		/*css鼠标悬停改变样式*/
		.search_btn:hover{
			color: #00aaff;
		}

		.transmit{
			padding: 3px;
			background-color:#f3f3f3;
			margin-left: 40px;
			margin-right: 40px;
			margin-bottom: 5px;
		}
		
		.transmit_name{
			padding: 3px;
			font-size: 16px;
			font-weight: bold;
		}

		.like_btn_liked{
			color: #00aaff;
		}

		.head_nickname_row{
			display: flex;
		}
		
		.head_nickname_size{
			font-size: 18px;
			font-weight: bold;
			flex: 1;
		}

		.delete_btn{
			width: 20px;
			font-family: "iconfont" !important;
			font-size: 18px;
			color: rgb(180,187,205);
			cursor: pointer;
		}
		.delete_btn:hover{
			color: #3879d9;
		}
		
		.time_size{
			
			color: rgb(180,187,205);
		}
		
		.transmit_name_content{
			padding: 3px;
			font-size: 15px;
			font-weight: bold;
		}
		
		.div_message_bottom{
			font-size: 15px;
			font-weight: 600;
		}
		
		.form-control{
			resize: none;
		}

		.bottom_row{
			text-align: center;
			padding-top: 16px;
			padding-bottom: 16px;
		}

		.load_more_btn{
			display:inline-block; 
			*display:inline; 
			*zoom:1;
			padding: 8px 24px 8px 24px;
			margin-left: auto;
			margin-right: auto;

			border: 1px solid #aaa;
			border-radius: 4px;
			color: #aaa;

			cursor: pointer;
		}
		#upload_image_button{
			width: 26px;
			font-family: 'iconfont' !important;
			color: #aaa;
			cursor: pointer;
			font-size: 20px;
			margin-left: 8px;
		}
		#upload_image_button:hover{
			color: #3879d9;
		}
		#preview_image{
			max-width: 200px;
			margin: 8px;
		}
		.weibo_message_image{
			width: 100%;
			margin-top: 4px;
			margin-bottom: 4px;
			background: #aaa;
		}
		.transmit_image{
			width: 100%;
			margin-top: 4px;
			margin-bottom: 4px;
			background: #aaa;
		}
		
		</style>
	</head>
	<body>	
	
	<!-- <div class="top" >
		<div class="top_left">
			<img class="logo" src="img/logo.png" />
		</div>
		<div class="top_mid">
			<input class="top_find" type="text" />
			<span class="search_btn">&#xe6a7;</span>
		</div>
		<div class="top_right">
			<img class="top_img" src="img/back.png" />
		</div>
	</div> -->
	<div id="nav_area">
	
</div>
	
	<div class ="mid">
		
		<!--内容的左边-->	
		<div class="mid_left">
			
			<!--微博内容编辑-->
			<div class="weibo_edit">
				<!--<div class="edit_top">
					<textarea class="textarea_edit" value="请编辑的的微博！">请编辑的的微博！</textarea>
				</div>-->
				
				<div style="padding: 5px;padding-top: 15px;">
					<textarea class="form-control" rows="3" id="comment_textarea" placeholder="分享你生活的点滴..."></textarea>
				</div>
				
				<div class="edit_bottom">
					<div class="edit_bottom_left">
						<div id="upload_image_button">&#xe623;</div>
						<input type="file" name="file" style="display: none;" id="img_uploader" onchange="imgchange()">
					</div>
					<div class="edit_bottom_right">
						<!-- <div class="edit_bottom_word_count"> -->
							
						<!-- </div> -->
						<span class="edit_bottom_word_count">
							<span id="word_counter">0</span> / 140
						</span>
						<!-- <input class="btn_send" type="button" value="发 送" /> -->
						<button class="send_btn">发送</button>

					</div>
					
					
				</div>
				<div class="upload_preview" style="display: none;">
					<span id="uploading_span">上传中...</span>
					<img id="preview_image">
				</div>
			</div>
			
			<!--<div class="weibo_message">
			    <!--<div class="weibo_top">
			        <div class="head_img">
			            <img class="weibo_message_img" src = "'+head_img+'"/>
			        </div><div class="head_nickname">
			        <div>'+thisData.nickname+'</div>
			        <div>'+formatDateTime(thisData.time)+'</div>
			        </div>
			    </div>-->
			    <!--<div class="div_message_mid">
			        <div class="textarea_message" >'+thisData.content+'</div>
			    </div>
			   <!-- <div class="transmit"><div class="transmit_name">@转发自某某某</div><div class="transmit_name">阿拉啦啦啦啦啦啦啦啦阿拉啦</div></div>
<!--<!--<!---->	
				<!--<div class="div_message_bottom">
			        <div class="btn_bottom">&#xe617; 转&nbsp;发</div>
			        <div class="btn_bottom">&#xe62f; 评  论</div>
			        <div class="btn_bottom">&#xe604; '+thisData.like_num+'</div>
			    </div>
			</div>-->
			
			<div id="weibo_area">

			</div>	
			<div class="bottom_row">
				<div class="load_more_btn">
					点击加载更多
				</div>
			</div>				
		</div>
								
		<!--微博的右部分-->
		<div class="mid_right">
			
			<div id="right_top">
				<div class="left_top"><div class="right_weibo_top">
					<div class="head_img"><a href="person.html" target="_blank"><img class="right_weibo_message_img" src = ""/></a></div><div class="head_nickname">
					<a href="person.html" target="_blank"><div class="right_nickname">'+thisData.nickname+'</div></a>
				</div></div><div class="friend_and_folloow">
					<div class="follow">
						<a href="person.html?t=1" target="_blank"><div id="right_follow_num">0</div><div>关  注 </div></a>
					</div>
					<div class="friend">
						<a href="person.html?t=2" target="_blank"><div id="right_fans_num">0</div><div>粉  丝</div></a>
					</div>
				</div></div>
			</div>
					
			<div id="right_bottom">
				<div class="left_bottom">
					<div class="right_common"><div class="right_common_in">
						地  区：<span class="area_common">'+thisData.area+'</span>
					</div></div>
					<div class="right_common"><div class="right_common_in">
						性 别：<span class="sex_span">'+thisData.sex+'</span>
					</div></div>
					<div class="right_common"><div class="right_common_in">
						生 日：<span class="birthday_span">'+thisData.birthday+'</span>
					</div></div>
					<div class="right_common"><div class="right_common_in">
						个性签名：<span class="signature_span">'+thisData.signature+'</span>
					</div></div>
				</div>
			</div>
	
		</div>
	</div>

	<!-- 转发模态框 -->
	<div class="modal fade" id="reblogModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">转发微博</h4>
      </div>
      <div class="modal-body">
          <div class="form-group">
            <!-- <label for="message-text" class="control-label">微博内容</label> -->
            <textarea class="form-control" id="reblog_textarea" placeholder="转发理由..."></textarea>
            
          </div>
          	<div style="text-align: right;">
				<span id="reblog_word_counter">0</span> / 140
			</div>
          <div class="transmit"><div class="transmit_name">@<span id="modal_nickname">转发自某某某</span></div><div class="transmit_name" id="modal_content">原微博内容</div></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" id="reblog_submit_btn">发送</button>
      </div>
    </div>
  </div>
</div>

<!-- 删除模态框 -->
	<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">删除微博</h4>
      </div>
      <div class="modal-body">
          确认删除这条微博?
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-danger" id="delete_comfirm_btn">删除</button>
      </div>
    </div>
  </div>
</div>
	<script src="nav.js"></script>
	<script>
		function formatDateTime(inputTime) {    
			var timeInt = parseInt(inputTime);
		    var date = new Date(timeInt);  
		    var y = date.getFullYear();    
		    var m = date.getMonth() + 1;    
		    m = m < 10 ? ('0' + m) : m;    
		    var d = date.getDate();    
		    d = d < 10 ? ('0' + d) : d;    
		    var h = date.getHours();  
		    h = h < 10 ? ('0' + h) : h;  
		    var minute = date.getMinutes();  
		    var second = date.getSeconds();  
		    minute = minute < 10 ? ('0' + minute) : minute;    
		    second = second < 10 ? ('0' + second) : second;   
		    return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;    
		}

		function loadUserInfo(){
			$.get('userinfo.do', function(data){
				try{
					var jsonObj = JSON.parse(data);
					if (jsonObj.error == 0) {
						var thisData = jsonObj.data;
						var head_img = 'img/head/' + thisData.head_image + ".jpg";
						$(".right_weibo_message_img").attr("src", head_img);
						$(".right_nickname").html(thisData.nickname);
						$("#right_follow_num").html(thisData.follow_num);
						$("#right_fans_num").html(thisData.fans_num);
						$(".area_common").html(thisData.area);

						var sex = "保密";
						if (thisData.sex == 1) {
							sex = "男";
						}else if (thisData.sex == 2) {
							sex = "女";
						}
						$(".sex_span").html(sex);

						$(".birthday_span").html(thisData.birthday);
						$(".signature_span").html(thisData.signature);

						loadBlog();

					}else if (jsonObj.error == 220) {
						window.location.href = "login.html";
					}else{
						alert(jsonObj.msg);
					}
				}catch(ex){
					alert(ex);
				}
			})
		}

		var weiboList = [];
		var page = 0;

		function loadBlog(){
			$.get('listBlog.do?m='+page*10+'&n='+(page+1)*10, function(data){
				console.log(data);
				var jsonObj = JSON.parse(data);
				var data = jsonObj.data;
				//weiboList = data;

				var weiboListHtml = "";
				if (data.length > 0) {
					for (var i = 0; i < data.length; i++) {
						var thisData = data[i];
						var head_img = 'img/head/' + thisData.head_image + ".jpg";
						var weiboHtml = '<div class="weibo_message"><div class="weibo_top"><div class="head_img"><a href="person.html?u='+thisData.user_id+'" target="_blank"><img class="weibo_message_img" src = "'+head_img+'"/></a></div><div class="head_nickname"><div class="head_nickname_row"><div class = "head_nickname_size"><a href="person.html?u='+thisData.user_id+'" target="_blank">'+thisData.nickname+'</a></div>'+(thisData.can_delete == '1'? '<div class="delete_btn" data-bid="'+thisData.blog_id+'" data-toggle="modal" data-target="#deleteModal">&#xe634;</div>':'')+'</div><div class = "time_size">'+formatDateTime(thisData.time)+'</div></div></div>';
						if (thisData.image != "") {
							weiboHtml += '<img src="img/uploads/'+thisData.image+'" class="weibo_message_image">';
						}
						var contentHtml = thisData.content.replace(/@(\S+)\s/g, '<a href="person.html?u=$1" style="color: #00aaff">@$1</a> ');
						weiboHtml += '<div class="div_message_mid"><div class="textarea_message" >'+contentHtml+'</div></div>';
						if(thisData.reblog_user_id != "") {
							// 显示转发的原微博
							weiboHtml += '<div class="transmit"><div class="transmit_name"><a href="detail.html?b='+thisData.reblog_id+'" target="_blank">@'+thisData.reblog_nickname+'</a></div>';
							if (thisData.reblog_image != "") {
								weiboHtml += '<img src="img/uploads/'+thisData.reblog_image+'" class="transmit_image">';
							}
							var reblogContentHtml = thisData.reblog_content.replace(/@(\S+)\s/g, '<a href="person.html?u=$1">@$1</a> ');
							weiboHtml += '<div class="transmit_name_content">'+reblogContentHtml+'</div></div>';
						}
							weiboHtml += '<div class="div_message_bottom"><div class="btn_bottom btn_reblog" data-bid="'+thisData.blog_id+'" data-toggle="modal" data-target="#reblogModal" data-reuser="'+thisData.nickname+'" data-recontent="'+thisData.content+'">&#xe617; 转&nbsp;发</div><div class="btn_bottom comment_btn" data-bid="'+thisData.blog_id+'">&#xe62f; 评  论</div><div class="btn_bottom like_btn'+(thisData.liked == "1" ? " like_btn_liked" : "")+'" data-bid="'+thisData.blog_id+'">&#xe604; <span class="like_btn_num">'+thisData.like_num+'</span></div></div></div>';

						weiboListHtml += weiboHtml;
					}
					$("#weibo_area").append(weiboListHtml);
					page += 1;

					// 以上列表元素会在载入后绑定点击事件
					$(".like_btn").click(function(){
						var _this = $(this);
						var bid = $(this).attr('data-bid');
						console.log(bid);
						if (!$(this).hasClass('like_btn_liked')) {
							// 未赞，现在点赞
							$.post('likeBlog.do',{
								blog_id: bid
							}, function(data){
								console.log(data);
								try{
									var jsonObj = JSON.parse(data);
									if (jsonObj.error == 0) {
										_this.addClass('like_btn_liked');
										var num_span = _this.find('.like_btn_num');
										var num = num_span.html();
										console.log(num);

										num_span.html(parseInt(num) + 1 + "");
									}
								}catch(ex){

								}
							})
						}else{
							// 已赞，现在取消点赞
							$.post('unlikeBlog.do',{
								blog_id: bid
							}, function(data){
								console.log(data);
								try{
									var jsonObj = JSON.parse(data);
									if (jsonObj.error == 0) {
										_this.removeClass('like_btn_liked');
										var num_span = _this.find('.like_btn_num');
										var num = num_span.html();
										console.log(num);

										num_span.html(parseInt(num) - 1 + "");
									}
								}catch(ex){

								}
							})

						}
					})

					$(".comment_btn").click(function(){
						window.open('detail.html?b='+$(this).attr("data-bid"));
					})
					if (data.length < 10) {
						$(".load_more_btn").text("没有更多了");
					}else{
						$(".load_more_btn").text("点击加载更多");
					}
					
				}else{
					$(".load_more_btn").text("没有更多了");
				}
				
			})
		}
		var reblogId = -1;
		var inputedReblog = "";
		
		$("#reblogModal").on('show.bs.modal', function(e){
			var button = $(e.relatedTarget);
			reblogId = button.data('bid');
			$("#modal_nickname").html(button.data('reuser'));
			$("#modal_content").html(button.data('recontent'));

			$("#reblog_textarea").val('');
			$("#reblog_textarea").focus();
		})

		$("#reblog_submit_btn").click(function(){
			if (inputedReblog.length == 0) {
				$("#reblog_textarea").focus();
				return;
			}
			if (reblogId == -1) {
				return;
			}

			reblogWeibo(inputedReblog, reblogId);

		})

		
		$(document).ready(function(){
			showNavBar();
			loadUserInfo();
		})
		
		//输入框计数
		function getBLen(str) {  
		    if (str == null) return 0;  
		    if (typeof str != "string"){  
		        str += "";  
		    }  
		    return str.replace(/[^\x00-\xff]/g,"01").length;  
		} 

		var inputedComment = "";
		// 这是微博textarea，因为从那边复制过来所以名字没有改
		$("#comment_textarea").bind('input propertychange', function(){
			// $("#submitBtn").removeAttr("disabled");
		
			// 计算个性签名字数
			var comment = $("#comment_textarea").val();
			var wordCount = getBLen(comment);
			if (wordCount > 140) {
				$("#comment_textarea").val(inputedComment);
			}else{
				inputedComment = comment;
			}
			$("#word_counter").text(getBLen($("#comment_textarea").val()));
		})

		$("#reblog_textarea").bind('input propertychange', function(){
			// $("#submitBtn").removeAttr("disabled");
		
			// 计算个性签名字数
			var comment = $("#reblog_textarea").val();
			var wordCount = getBLen(comment);
			if (wordCount > 140) {
				$("#reblog_textarea").val(inputedReblog);
			}else{
				inputedReblog = comment;
			}
			$("#reblog_word_counter").text(getBLen($("#reblog_textarea").val()));
		})

		$(".send_btn").click(function(){
			if (imageToSend == "") {
				if (inputedComment.length == 0) {
					$("#comment_textarea").focus();
					return;
				}
			}
			

			postWeibo(inputedComment);
		})

		function postWeibo(content){
			$.post('postBlog.do', {
				content: content,
				image: imageToSend
			}, function(data){
				try{
					var jsonObj = JSON.parse(data);
					if (jsonObj.error == 0) {
						imageToSend = "";
						$(".upload_preview").hide();
						$("#comment_textarea").val('');
						inputedComment = '';
						$("#word_counter").text('0');
						page = 0;
						$("#weibo_area").html('');
						loadBlog();
					}else if (jsonObj.error == 220) {
						window.location.href = "login.html";
					}else{
						alert('系统异常，请稍后重试');
					}
				}catch(ex){
					console.log(ex);
					alert('系统异常，请稍后重试');
				}
			})
		}

		function reblogWeibo(content, blogId){
			$.post('postBlog.do', {
				content: content,
				reblog_id: blogId
			}, function(data){
				try{
					var jsonObj = JSON.parse(data);
					if (jsonObj.error == 0) {

						reblogId = -1;
						$("#reblog_textarea").val('');
						inputedReblog = '';
						$("#reblogModal").modal('hide');

						page = 0;
						$("#weibo_area").html('');
						loadBlog();

					}else if (jsonObj.error == 220) {
						window.location.href = "login.html";
					}else{
						alert('系统异常，请稍后重试');
					}
				}catch(ex){
					console.log(ex);
					alert('系统异常，请稍后重试');
				}
			})
		}

		$(".load_more_btn").click(function(){
			loadBlog();
		})

		var deleteBlogId = -1;
		$("#deleteModal").on('show.bs.modal', function(e){
			var button = $(e.relatedTarget);
			deleteBlogId = button.data('bid');
		})

		$("#delete_comfirm_btn").click(function(){
			if (deleteBlogId == -1) {
				return;
			}

			$.post('deleteWeibo.do', {
				blog_id: deleteBlogId
			}, function(data){
				try{
					console.log(data);
					var jsonObj = JSON.parse(data);
					if (jsonObj.error == 0) {
						deleteBlogId = -1;
						page = 0;
						$("#weibo_area").html('');
						loadBlog();
						$("#deleteModal").modal('hide');
					}else if (jsonObj.error == 220) {
						window.location.href = "index.html";
					}else{
						alert('系统异常，请稍后重试');
					}
				}catch(ex){
					console.log(ex)
					alert('系统异常，请稍后重试');
				}
			})
		})

		$("#upload_image_button").click(function(){
			$("#img_uploader").click();
		})

var imageToSend = "";

function imgchange() {  
  
    var localimg = $("#img_uploader").get(0).files[0];  

    if(!localimg){  
        return;  
    }  

    var fileName = localimg.name;  
    var fileSize = localimg.size;  
    var fileType=fileName.substring(fileName.lastIndexOf('.'),fileName.length).toLowerCase();  
    if(fileType!='.gif' && fileType!='.jpeg' && fileType!='.png' && fileType!='.jpg')  
    {  
        alert("上传失败，请上传jpg,png格式的图片");  
        return;  
    }  

    var size=3*1024*1024;  
    if(fileSize>size){  
        alert("上传失败，请上传3MB以内的图片。");  
        return;  
    }  
    $(".upload_preview").show();
    $("#uploading_span").show();
    $("#preview_image").hide();
    $("#uploading_span").html("上传中...");
	
	var formdata = new FormData();
	formdata.append("file", localimg);

	$.ajax({
    	url: 'uploadImg.do',
    	type: 'POST',
    	contentType: false,
    	processData: false,
    	cache: false,
    	data: formdata,
    	xhr: function(){
    		myXhr = $.ajaxSettings.xhr();
			if(myXhr.upload){ //检查upload属性是否存在
				//绑定progress事件的回调函数
				myXhr.upload.addEventListener('progress',progressHandlingFunction, false);
			}
			return myXhr; //xhr对象返回给jQuery使用
    	},
    	success: function(data){
    		try{
	    		var jsonObj = JSON.parse(data);
	    		if (jsonObj.error == 0) {
	    			
			        var fileInput = $("#img_uploader");
			        fileInput.after(fileInput.clone().val(''));
			        fileInput.remove();
			        
			        $("#uploading_span").hide();
			        $("#preview_image").attr("src", "");
			        $("#preview_image").attr("src", 'img/uploads/'+jsonObj.data);
			        $("#preview_image").show();
			        imageToSend = jsonObj.data;
	    		}else if (jsonObj.error == 220) {
	    			window.location.href = "login.html";
	    		}else{
	    			// alert("系统异常，请稍后重试");
	    			$("#uploading_span").html("上传失败");
	    		}
	    	}catch(ex){
	    		$("#uploading_span").html("上传失败");
	    	}
    	}
    })


}

//上传进度回调函数：
function progressHandlingFunction(e) {
	if (e.lengthComputable) {
		var percent = Math.floor(e.loaded/e.total*100);
		$("#uploading_span").html("上传中...("+percent+"%)")
	}
}

	</script>
	
	</body>
</html>
